//
//  ViewController.m
//  Oc_Ui_Noob_XZL_Locke
//
//  Created by 江山 on 15/11/15.
//  Copyright © 2015年 hi. All rights reserved.
//

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "TestViewController.h"
#import "Test2ViewController.h"
@interface ViewController ()
//设置全局变量
//否则每次使用都必须先声明
{
    UILabel * l;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置UIWindow的背景色
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"我的标题栏";
    
    //UILabel 设置标签显示文本
    l = [UILabel new];
    
    //内容
    l.text = @"你好,世界!";
    
    //sizeToFit意思是 当前视图边界和边界大小(自动根据文本的长度改变自身的长度)
    [l sizeToFit];
    
    //显示位置
    l.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0);
    //文本文字颜色
    l.textColor = [UIColor greenColor];
    
    [self.view addSubview:l];
    
    //创建按钮(UIButton)
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //按钮放置位置
    btn.frame = CGRectMake(100, 100, 200, 44);
    //按钮标签？
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    //标签文字颜色？UIControlStateNormal代表控件处于正常状态(取正常状态)
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //设置点击事件
    //Target...action 设计模式,就是当某个时间发生时,调用那个对象中的方法
    [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    
    UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn1.frame = CGRectMake(100, 150, 200, 44);
    [btn1 setTitle:@"按钮2" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(onClick1:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
}

//按钮触发事件
- (void)onClick:(id)sender
{
    //调用类创建表格
    TestViewController * con = [TestViewController new];
    //导航栏与视图控制器之间的切换
    [self.navigationController pushViewController:con animated:YES];
}

- (void)onClick1:(id)sender{
    Test2ViewController * con= [Test2ViewController new];
    [self.navigationController pushViewController:con animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
